
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>设备借还申请</title>
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css?20190817.1">
    <link rel="stylesheet" href="/lib/layui/layui/css/common.css">
    <script src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/global.js"></script>
    <script type="text/javascript" src="../../js/jquery/jquery-1.9.1.js"></script>
    <script src="../../js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/layui/layui/js/baseCode/base.js?v=201908121454" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/layui/layui/js/common.js?v=201907231346" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../lib/ueditor/ueditor.config.js" type="text/javascript" charset="utf-8"></script>
    <script src="../lib/ueditor/ueditor.all.js" type="text/javascript" charset="utf-8"></script>
    <style>
        .mbox {
            padding: 8px;
        }
        .inbox {
            padding: 5px;
            padding-right: 30px;
        }
        .layui-btn {
            margin-left: 10px;
        }
        .layui-btn .layui-icon {
            margin-right: 0px;
        }
        .red {
            color: red;
            font-size: 16px;
        }
        .layui-form-label {
            padding: 8px 15px;
        }
        .layui-card-body {
            display: flex;
            padding: 0px;
        }
        .layui-lf {
            min-width: 10%;
            overflow-x: auto;
        }
        .layui-rt {
            width: 100%;
        }
        .layui-form-select .layui-input{
            height: 32px;
        }
        .layui-tab-title{
            height: 32px;
        }

        .layui-tab-title li{
            height: 33px;
            line-height: 33px;
        }
        .layui-tab layui-tab-card{
            margin-top: -4px;
        }
        .layui-tab-card>.layui-tab-title .layui-this:after {
            border-width: 0px;
        }
        .layui-table{
            margin-top: -2px !important;
        }
        .layui-table-view .layui-table td, .layui-table-view .layui-table th{
            padding: 2px 0;
        }
        #infoId td{
            padding: 5px 2px;
        }
        .tablecolor{
            background-color:#f2f2f2;
        }
        .layui-table{
            width:100%!important;
        }
        .bg{
            background-color: #F2F2F2;
        }
    </style>
</head>
<body>
<div class="mbox">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-rt">
                <div class="layui-tab layui-tab-card" lay-filter="tabtoggle">
                    <ul class="layui-tab-title">
                        <li class="layui-this">转移申请</li>
                        <li>待批申请</li>
                        <li>已准申请</li>
                        <li>未准申请</li>
                    </ul>
                    <%--页签下面内容--%>
                    <div class="layui-tab-content" style="height:100%;padding: 0 10px 10px 10px">
                        <div class="layui-tab-item layui-show">
                            <table class="layui-table" lay-skin="line" id="Settlement" lay-size="sm" lay-filter="SettlementFilter"></table>
                            <div class="layui-tab layui-tab-card" lay-filter="bottomTab" style="position: relative;z-index: 0;">
                                <ul class="layui-tab-title">
                                    <li class="layui-this">转移设备明细</li>
                                </ul>
                                <div class="layui-tab-content" style="padding: 0 10px">
                                    <div class="layui-tab-item layui-show">
                                        <table class="layui-table" id="transferDetail" lay-filter="transferFilter" lay-size="sm"></table>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <table class="layui-table" lay-skin="line" id="accurateTable" lay-size="sm" lay-filter="accurateTableFilter"></table>
                            <div class="layui-tab layui-tab-card" lay-filter="bottomTab" style="position: relative;z-index: 0;">
                                <ul class="layui-tab-title">
                                    <li class="layui-this">转移设备明细</li>
                                </ul>
                                <div class="layui-tab-content" style="padding: 0 10px">
                                    <div class="layui-tab-item layui-show">
                                        <table id="accurateDetail" lay-filter="accurateFilter" lay-size="sm"></table>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <table class="layui-table" lay-skin="line" id="approvalTable" lay-size="sm" lay-filter="approvalTableFilter"></table>
                            <div class="layui-tab layui-tab-card" lay-filter="bottomTab" style="position: relative;z-index: 0;">
                                <ul class="layui-tab-title">
                                    <li class="layui-this">转移设备明细</li>
                                </ul>
                                <div class="layui-tab-content" style="padding: 0 10px">
                                    <div class="layui-tab-item layui-show">
                                        <table id="approvalDetail" lay-filter="approvalFilter" lay-size="sm"> </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <table class="layui-table" lay-skin="line" id="notexactlyTable" lay-size="sm" lay-filter="notexactlyTableFilter"></table>
                            <div class="layui-tab layui-tab-card" lay-filter="bottomTab" style="position: relative;z-index: 0;">
                                <ul class="layui-tab-title">
                                    <li class="layui-this">转移设备明细</li>
                                </ul>
                                <div class="layui-tab-content" style="padding: 0 10px">
                                    <div class="layui-tab-item layui-show">
                                        <table id="notexactlyDetail" lay-filter="notexactlyFilter" lay-size="sm"> </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<%--借还申请新增/批量删除/查询字段--%>
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="submit" style="width: 70px">提交</button>
        <button class="layui-btn layui-btn-sm" lay-event="add" style="width: 70px" id="add">新建</button>
        <button class="layui-btn layui-btn-sm" lay-event="del" style="width: 70px">删除</button>
    </div>
    <div class="demoTable" style="position:absolute;right: 8%;top: 10px;width: 600px;height: 30px">
        <label style="float: left;width: 60px;">查询字段</label>
        <div class="layui-input-inline" style="float:left;">
            <select name="modules" lay-verify="required" lay-filter="serachInfo"lay-search="" placeholder="请选择" style="height: 10px">
                <option value="0">请选择查询字段</option>
                <option value="PROJECT_NO">立项编号</option>
                <option value="APPLICANT">报废申请人</option>
                <option value="SCRAP_REASON">报废原因</option>
                <option value="WORKFLOW_NO">流水号</option>
            </select>
        </div>
        <div style="float: left">
            <div class="layui-inline">
                <input class="layui-input" name="searchtext"  autocomplete="off" style="height: 32px;margin-left: 6px;">
            </div>
            <button class="layui-btn" data-type="reload"   lay-event="searchCust" style="height:30px;line-height: 30px; ">搜索</button>
        </div>
    </div>
</script>
<%--查询字段（待批）--%>
<script type="text/html" id="approval">
    <div class="demoTabless" style="position:absolute;right: 8%;top: 10px;width: 600px;height: 30px">
        <label style="float: left;width: 60px;">查询字段</label>
        <div class="layui-input-inline" style="float:left;">
            <select name="modules" lay-verify="required" lay-filter="serachInfo"  placeholder="请选择" lay-search="" style="height: 10px">
                <option value="0">请选择查询字段</option>
                <option value="DEPT_ID">报废部门</option>
                <option value="APPLICANT">报废申请人</option>
                <option value="SCRAP_REASON">报废原因</option>
                <option value="WORKFLOW_NO">流水号</option>
            </select>
        </div>
        <div style="float: left">
            <div class="layui-inline">
                <input class="layui-input" name="searchtextss" autocomplete="off" style="height: 32px;margin-left: 6px;">
            </div>
            <button class="layui-btn" data-type="reload"  lay-event="searchCustss" style="height:30px;line-height: 30px;">搜索</button>
        </div>
    </div>
</script>
<%--查询字段（已准）--%>
<script type="text/html" id="accurate">
    <div class="demoTablea" style="position:absolute;right: 8%;top: 10px;width: 600px;height: 30px">
        <label style="float: left;width: 60px;">查询字段</label>
        <div class="layui-input-inline" style="float:left;">
            <select name="modules" lay-verify="required" lay-filter="serachInfo"  placeholder="请选择" lay-search="" style="height: 10px">
                <option value="0">请选择查询字段</option>
                <option value="DEPT_ID">报废部门</option>
                <option value="APPLICANT">报废申请人</option>
                <option value="SCRAP_REASON">报废原因</option>
                <option value="WORKFLOW_NO">流水号</option>
            </select>
        </div>
        <div style="float: left">
            <div class="layui-inline">
                <input class="layui-input" name="searchtexta" autocomplete="off" style="height: 32px;margin-left: 6px;">
            </div>
            <button class="layui-btn" data-type="reload"  lay-event="searchCusta" style="height:30px;line-height: 30px;">搜索</button>
        </div>
    </div>
</script>
<%--查询字段（未批）--%>
<script type="text/html" id="notexactly">
    <div class="demoTableb" style="position:absolute;right: 8%;top: 10px;width: 600px;height: 30px">
        <label style="float: left;width: 60px;">查询字段</label>
        <div class="layui-input-inline" style="float:left;">
            <select name="modules" lay-verify="required" lay-filter="serachInfo"  placeholder="请选择" lay-search="" style="height: 10px">
                <option value="0">请选择查询字段</option>
                <option value="DEPT_ID">报废部门</option>
                <option value="APPLICANT">报废申请人</option>
                <option value="SCRAP_REASON">报废原因</option>
                <option value="WORKFLOW_NO">流水号</option>
            </select>
        </div>
        <div style="float: left">
            <div class="layui-inline">
                <input class="layui-input" name="searchtextb" autocomplete="off" style="height: 32px;margin-left: 6px;">
            </div>
            <button class="layui-btn" data-type="reload"  lay-event="searchCustb" style="height:30px;line-height: 30px;">搜索</button>
        </div>
    </div>
</script>
<%--借还设备明细下头部--%>
<script type="text/html" id="toolbars">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="addtail" style="width: 70px">新建</button>
        <button class="layui-btn layui-btn-sm"  style="width: 70px" lay-event="deltail">删除</button>
    </div>
</script>
<%--借还申请上头部--%>
<script type="text/html" id="barOperation">
    <a class="layui-btn  layui-btn-xs" lay-event="sub" id="sub">提交</a>
    <a class="layui-btn  layui-btn-xs" lay-event="edit" id="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/html" id="barOperation1">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" hide="true">删除</a>
</script>
<script type="text/javascript">

    var settlementTable,
        accurateTable,
        approvalTable,
        notexactlyTable,
        acceptTable,
        transferDetail;
    var topindexPage=0;
    var deptId;
    var addId;
    var eddata;
    var col = [[
        {type: 'checkbox'}
        , {field: 'equipName', title: '设备名称'}
        , {field: 'equipNo', title: '固定资产编号'}
        , {field: 'factoryNo', title: '出厂编号'}
        , {field: 'equipTypeName', title: '设备类型'}
        , {field: 'equipStatusName', title: '资产状态'}
        , {field: 'modelNo', title: '型号'}
        , {field: 'spec', title: '规格'}
        //, {field: 'scrapReason', title: '报废原因'}
        //, {field: 'memo', title: '备注'}
    ]];
    var ccol = [[
        , {field: 'equipName', title: '设备名称'}
        , {field: 'equipNo', title: '固定资产编号'}
        , {field: 'factoryNo', title: '出厂编号'}
        , {field: 'equipTypeName', title: '设备类型'}
        , {field: 'equipStatusName', title: '资产状态'}
        , {field: 'modelNo', title: '型号'}
        , {field: 'spec', title: '规格'}
        //, {field: 'scrapReason', title: '报废原因'}
        //, {field: 'memo', title: '备注'}
    ]];
    layui.use(['table', 'layer','laydate', 'form', 'element'], function () {
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        var element = layui.element;
        var laydate = layui.laydate;

        //转移申请表格实例
        settlementTable = table.render({
            elem: '#Settlement'
            , page: true //开启分页
            , url: '/equipmentScrapping/showScraplogNew'//数据接口
            , toolbar: '#toolbar'
            , cols: [[ //标题栏
                    {type: 'checkbox'}
                    , {field: 'scraplogId', title: '申请编号'}
                    , {field: 'applicant', title: '报废申请人'}
                    , {field: 'deptName', title: '报废申请部门'}
                    , {field: 'applicantTime', title: '报废申请时间',templet: function(d) {
                            return format(d.applicantTime)
                        }}
                    , {field: 'workflowNo', title: '流水号'}
                    , {field: 'scrapReason', title: '报废原因'}
                    , {field: 'memo', title: '备注'}
                    , {width: 200, title: '操作', align: 'center', toolbar: '#barOperation'}
                ]]
            , limit: 10
            ,done:function (res) {
                if(res.data.length >0){
                    var scraplogId = res.data[0].scraplogId;
                    equipTable("#transferDetail",scraplogId,"#toolbars",col);
                }else{
                    cequipTable("#transferDetail","#toolbars",col);
                }
            }
        })
        //待批申请表格实例
        accurateTable = table.render({
            elem: '#accurateTable'
            , url: ''
            , page: true //开启分页
            , toolbar: '#approval'
            , limit: 5 //每页默认显示的数量
            , limits: [5, 10, 15, 20, 25, 30]
            , cols: [[ //标题栏
                {field: 'scraplogId', title: '申请编号'}
                , {field: 'applicant', title: '报废申请人'}
                , {field: 'deptName', title: '报废申请部门'}
                , {field: 'applicantTime', title: '报废申请时间',templet: function(d) {
                        return format(d.applicantTime)
                    }}
                , {field: 'workflowNo', title: '流水号'}
                , {field: 'scrapReason', title: '报废原因'}
                , {field: 'memo', title: '备注'}
            ]]
            ,done:function (res) {
                if(res.data.length >0){
                    var scraplogId = res.data[0].scraplogId;
                    equipTable("#accurateDetail",scraplogId,"#",ccol)
                }else{
                    cequipTable("#accurateDetail","#",ccol)
                }
            }
        });
        //已准申请表格实例
        approvalTable = table.render({
            elem: '#approvalTable'
            , url: ''
            , page: true //开启分页
            , toolbar: '#accurate'
            , limit: 5 //每页默认显示的数量
            , limits: [5, 10, 15, 20, 25, 30]
            , cols: [[ //标题栏
                {field: 'scraplogId', title: '申请编号'}
                , {field: 'applicant', title: '报废申请人'}
                , {field: 'deptName', title: '报废申请部门'}
                , {field: 'applicantTime', title: '报废申请时间',templet: function(d) {
                        return format(d.applicantTime)
                    }}
                , {field: 'workflowNo', title: '流水号'}
                , {field: 'scrapReason', title: '报废原因'}
                , {field: 'memo', title: '备注'}
            ]]
            ,done:function (res) {
                if(res.data.length >0){
                    var scraplogId = res.data[0].scraplogId
                    equipTable("#approvalDetail",scraplogId,"#",ccol)
                }else{
                    cequipTable("#approvalDetail","#",ccol)
                }
            }
        });
        //未准表格实例
        notexactlyTable = table.render({
            elem: '#notexactlyTable'
            , url: ''
            , toolbar: '#notexactly'
            , page: true //开启分页
            , limit: 5 //每页默认显示的数量
            , limits: [5, 10, 15, 20, 25, 30]
            , cols: [[ //标题栏
                {field: 'scraplogId', title: '申请编号'}
                , {field: 'applicant', title: '报废申请人'}
                , {field: 'deptName', title: '报废申请部门'}
                , {field: 'applicantTime', title: '报废申请时间',templet: function(d) {
                        return format(d.applicantTime)
                    }}
                , {field: 'workflowNo', title: '流水号'}
                , {field: 'scrapReason', title: '报废原因'}
                , {field: 'memo', title: '备注'}
            ]]
            ,done:function (res) {
                if(res.data.length >0){
                    var scraplogId = res.data[0].scraplogId;
                    equipTable("#notexactlyDetail",scraplogId,"#",ccol)
                }else{
                    cequipTable("#notexactlyDetail","#",ccol)
                }
            }
        });

        //顶部页签切换事件
        element.on('tab(tabtoggle)', function (data) {
            var index = data.index;
            topindexPage=data.index;
            switch (index) {
                case 0:
                    settlementTable.reload({
                        url:'/equipmentScrapping/showScraplogNew'
                    })
                    break;
                case 1:
                    accurateTable.reload({
                        url:'/equipmentScrapping/showScraplogWait'
                    })
                    break;
                case 2:
                    approvalTable.reload({
                        url:'/equipmentScrapping/showScraplogYes'
                    })
                    break;
                case 3:
                    notexactlyTable.reload({
                        url:'/equipmentScrapping/showScraplogNo'
                    })
                    break;
            }
        });
        // 转移申请头部事件
        table.on('toolbar(SettlementFilter)', function (obj) {
            var layEvent = obj.event;
            switch (layEvent) {
                case 'submit':
                    var subdata = table.checkStatus('Settlement').data;
                    var scrIds = "";
                    for (var i = 0; i < subdata.length; i++) {
                        scrIds += subdata[i].scraplogId + ",";
                    }
                    if (subdata.length == 0 || subdata.length < 0) {
                        layer.msg("请选择一条或者多条进行提交。");
                        return false;
                    } else if (subdata.length > 0) {
                        layer.confirm('确认要提交吗？', {
                            btn: ['确认', '取消'],
                            icon: 7,
                            title: "系统提示"
                        }, function () {
                            $.ajax({
                                type: "post",
                                url: "/equipmentScrapping/submitDate",
                                dataType: "json",
                                data: {
                                    ids: scrIds,
                                },
                                success: function (res) {
                                    if (res.code == 0) {
                                        layer.msg(res.msg);
                                        settlementTable.reload();
                                    } else {
                                        layer.msg(res.msg);
                                    }
                                }
                            })
                        }, function () {
                            layer.closeAll();
                        });
                    }
                    break;
                case 'add':
                    layer.open({
                        type: 2,
                        skin: false, //加上边框
                        area: ['100%', '100%'], //宽高
                        title: '新增申请',
                        maxmin: true,
                        btn: ["确定", "取消"],
                        content: '/equipmentScrapping/addScrapMsg?begin=add'
                        , success: function (res) {

                        },
                        yes: function (index, layero) {
                            var arr =[];
                            var jsondata = $(layero).find("iframe")[0].contentWindow.addjData();
                            var jsonlist = JSON.stringify(jsondata);
                            var log = $(layero).find("iframe")[0].contentWindow.addData();
                            arr.push(log);
                            var jsonlog = JSON.stringify(arr);
                            if (jsondata.length == 0 || log.deptName == "" || log.applicant == "" || log.applicantTime == "") {
                                layer.msg("请填写完整的信息再添加！");
                                return false;
                            } else {
                                layer.close(index);
                                $.ajax({
                                    type: "post",
                                    url: "/equipmentScrapping/addScraplogAndScraplist",
                                    dataType: "json",
                                    data: {
                                        jsonlist:jsonlist,
                                        jsonlog:jsonlog
                                    },
                                    success: function (res) {
                                        if (res.code == 0) {
                                            layer.msg(res.msg);
                                            settlementTable.reload();
                                        } else {
                                            layer.msg(res.msg);
                                        }
                                    }
                                })

                            }
                        }
                    });
                    break;
                case 'del':
                    var deldata = table.checkStatus('Settlement').data;
                    var ids = ""
                    for (var i = 0; i < deldata.length; i++) {
                        ids += deldata[i].scraplogId + ",";
                    }
                    if (deldata.length == 0 || deldata.length < 0) {
                        layer.msg("请选择一条或者多条进行删除。");
                        return false;
                    } else if (deldata.length > 0) {
                        layer.confirm('确认要删除吗？', {
                            btn: ['确认', '取消'],
                            icon: 7,
                            title: "系统提示"
                        }, function () {
                            $.ajax({
                                type: "post",
                                url: "/equipmentScrapping/delectScraplog",
                                dataType: "json",
                                data: {
                                    ids: ids
                                },
                                success: function (res) {
                                    if (res.code == 0) {
                                        layer.msg(res.msg);
                                        settlementTable.reload();
                                    } else {
                                        layer.msg(res.msg);
                                    }
                                }
                            })
                        }, function () {
                            layer.closeAll();
                        });
                    }
                    break;
                case 'searchCust':
            var inptext=$(".demoTable input[name='searchtext']").val();
            var seletext=$(".demoTable").find("dl dd.layui-this").attr("lay-value");
            console.log(seletext)
            if((inptext == "")&&(seletext==undefined)){
                layer.msg("请输入需要搜索的条件");
                return false;
            }else if((inptext=="")&&(seletext!=undefined)){
                layer.msg("请输入需要查询的条件");
                return false;
            }else if((inptext!="")&&(seletext==undefined)){
                layer.msg("请选择查询的字段");
                return false;
            }else{
                var datas={
                    inptext:inptext,
                    column:seletext
                }
                searchCusInfo(datas)
            }
                    break;
            }

        });
        //转移申请表格行事件
        table.on('row(SettlementFilter)', function (obj) {
            var events = obj.event;
            var data = obj.data;
            eddata = obj.data;
            deptId = data.deptId;
            addId = data.scraplogId;
            var index = $(this).attr('data-index');
            var tr = $(this).parent().children("tr");
            $(this).addClass("bg");
            for (var i = 0; i < tr.length; i++) {
                if (index != i) {
                    tr.eq(i).removeClass("bg");
                }
            };
            equipTable("#transferDetail",data.scraplogId,"#toolbars",col)
        })
        //待批表格行事件
        table.on('row(approvalTableFilter)', function (obj) {
            var events = obj.event;
            var data = obj.data;
            var index = $(this).attr('data-index');
            var tr = $(this).parent().children("tr");
            $(this).addClass("bg");
            for (var i = 0; i < tr.length; i++) {
                if (index != i) {
                    tr.eq(i).removeClass("bg");
                }
            };
            equipTable("#approvalDetail",data.scraplogId,"#",ccol)
        })
        //已准表格行事件
        table.on('row(accurateTableFilter)', function (obj) {
            var events = obj.event;
            var data = obj.data;
            var index = $(this).attr('data-index');
            var tr = $(this).parent().children("tr");
            $(this).addClass("bg");
            for (var i = 0; i < tr.length; i++) {
                if (index != i) {
                    tr.eq(i).removeClass("bg");
                }
            };
            equipTable("#accurateDetail",data.scraplogId,"#",ccol)
        })
        //未准表格行事件
        table.on('row(notexactlyTableFilter)', function (obj) {
            var events = obj.event;
            var data = obj.data;
            var index = $(this).attr('data-index');
            var tr = $(this).parent().children("tr");
            $(this).addClass("bg");
            for (var i = 0; i < tr.length; i++) {
                if (index != i) {
                    tr.eq(i).removeClass("bg");
                }
            };
            equipTable("#notexactlyDetail",data.scraplogId,"#",ccol)
        })
        // 转移申请行内操作事件
        table.on('tool(SettlementFilter)', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if (layEvent == 'sub') {
                var scrIds = data.scraplogId + ",";
                layer.confirm('确认要提交吗？', {
                    btn: ['确认', '取消'],
                    icon: 7,
                    title: "系统提示"
                }, function () {
                    $.ajax({
                        type: "post",
                        url: "/equipmentScrapping/submitDate",
                        dataType: "json",
                        data: {
                            ids: scrIds,
                        },
                        success: function (res) {
                            if (res.code == 0) {
                                layer.msg(res.msg);
                                settlementTable.reload();
                            } else {
                                layer.msg(res.msg);
                            }
                        }
                    })
                }, function () {
                    layer.closeAll();
                });
            }else if(layEvent === 'edit'){
                layer.open({
                    type: 2,
                    skin: false, //加上边框
                    area: ['90%', '90%'], //宽高
                    title: '编辑',
                    maxmin: true,
                    btn: ["确定", "取消"],
                    btnAlign: 'c',
                    content: '/equipmentScrapping/addScrapMsg?begin=edit&scraplogId='+data.scraplogId
                    , success: function (res) {

                    },
                    yes: function (index, layero) {
                        var arr = [];
                        var jsondata = $(layero).find("iframe")[0].contentWindow.addData();
                        arr.push(jsondata);
                        var jsonlog = JSON.stringify(arr);
                        // jsonlog.scraplogId = data.scraplogId;
                        if (jsonlog.deptName == "" || jsonlog.applicant == "" || jsonlog.applicantTime == "") {
                            layer.msg("请填写完整的信息添加！");
                            return false;
                        } else {
                            layer.close(index);
                            $.ajax({
                                type:"post",
                                url:"/equipmentScrapping/modifyData",
                                dataType:"json",
                                data: {
                                    jsonlog:jsonlog,
                                    scraplogId:data.scraplogId
                                },
                                success:function(res){
                                    if (res.code == 0) {
                                        layer.msg(res.msg);
                                        settlementTable.reload();
                                    } else {
                                        layer.msg(res.msg);
                                    }
                                }
                            })
                            // $.ajax({
                            //     type: "post",
                            //     url: "/equipmentScrapping/modifyData",
                            //     dataType: "json",
                            //     data: {
                            //         jsonlog:jsonlog,
                            //         scraplogId:data.scraplogId
                            //     },
                            //     success: function (res) {
                            //         if (res.code == 0) {
                            //             layer.msg(res.msg);
                            //             // jsonlog.reload();
                            //         } else {
                            //             layer.msg(res.msg);
                            //         }
                            //     }
                            // })
                        }
                    }
                })
            } else if (layEvent === 'del') {
                var ids = data.scraplogId + ",";
                layer.confirm('确认要删除吗？', {
                    btn: ['确认', '取消'],
                    icon: 7,
                    title: "系统提示"
                }, function () {
                    $.ajax({
                        type: "post",
                        url: "/equipmentScrapping/delectScraplog",
                        dataType: "json",
                        data: {
                            ids: ids
                        },
                        success: function (res) {
                            if (res.code == 0) {
                                layer.msg(res.msg);
                                settlementTable.reload();
                            } else {
                                layer.msg(res.msg);
                            }
                        }
                    })
                }, function () {
                    layer.closeAll();
                });
            }
        });
        // 转移申请下面设备明细头部事件
        table.on('toolbar(transferFilter)', function (obj) {
            var layEvent = obj.event;
            switch (layEvent) {
                case 'addtail':
                    if(deptId == undefined || deptId == "undefined"){
                        layer.msg("请选择需要修改设备信息的申请");
                        return false;
                    }else{
                        layer.open({
                            type: 2,
                            skin: false, //加上边框
                            area: ['100%', '100%'], //宽高
                            title: '编辑设备信息',
                            maxmin: true,
                            btn: ["确定", "取消"],
                            btnAlign: 'c',
                            content: '/equipmentScrapping/addEquipmentg?deptId='+deptId
                            , success: function (res) {

                            },
                            yes: function (index, layero) {
                                var jsondata = $(layero).find("iframe")[0].contentWindow.getData();
                                var jsonlist = JSON.stringify(jsondata);
                                if (jsondata.length == 0) {
                                    layer.msg("请选择需要添加的数据！");
                                    return false;
                                } else {
                                    layer.close(index);
                                    $.ajax({
                                        type: "post",
                                        url: "/equipmentScrapping/addScraplist",
                                        dataType: "json",
                                        data: {
                                            jsonlist:jsonlist,
                                            scraplogId:addId
                                        },
                                        success: function (res) {
                                            if (res.code == 0) {
                                                layer.msg(res.msg);
                                                equipTable("#transferDetail",addId,"#toolbars",col);
                                            } else {
                                                layer.msg(res.msg);
                                            }
                                        }
                                    })
                                }
                            }
                        })
                    }
                    break;
                case 'deltail':
                    var deldata = layui.table.checkStatus('transferDetail').data;
                    var ids = ""
                    for (var i = 0; i < deldata.length; i++) {
                        ids += deldata[i].scraplistId + ",";
                    }
                    if (deldata.length == 0 || deldata.length < 0) {
                        layer.msg("请选择一条或者多条进行删除。");
                        return false;
                    } else if (deldata.length > 0) {
                        layer.confirm('确认要删除吗？', {
                            btn: ['确认', '取消'],
                            icon: 7,
                            title: "系统提示"
                        }, function () {
                            $.ajax({
                                type: "post",
                                url: "/equipmentScrapping/delectScraplist",
                                dataType: "json",
                                data: {
                                    ids:ids
                                },
                                success: function (res) {
                                    if (res.code == 0) {
                                        layer.msg(res.msg);
                                        table.reload('transferDetail')
                                        // settlementTable.reload();
                                    } else {
                                        layer.msg(res.msg);
                                    }
                                }
                            })
                        }, function () {
                            layer.closeAll();
                        });
                    }
                    break;
            }
        });

        //待批
        table.on('toolbar(accurateTableFilter)', function (obj) {
            var layEvent = obj.event;
            switch (layEvent) {

                case 'searchCustss':
                    var inptext=$(".demoTabless input[name='searchtextss']").val();
                    var seletext=$(".demoTabless").find("dl dd.layui-this").attr("lay-value");
                    console.log(seletext)
                    if((inptext == "")&&(seletext==undefined)){
                        layer.msg("请输入需要搜索的条件");
                        return false;
                    }else if((inptext=="")&&(seletext!=undefined)){
                        layer.msg("请输入需要查询的条件");
                        return false;
                    }else if((inptext!="")&&(seletext==undefined)){
                        layer.msg("请选择查询的字段");
                        return false;
                    }else{
                        var datas={
                            inptext:inptext,
                            column:seletext
                        }
                        searchCusInfo(datas)
                    }
                    break;
            }
        });
        // 已批头部事件
        table.on('toolbar(approvalTableFilter)', function (obj) {
            var layEvent = obj.event;
            switch (layEvent) {
                case 'searchCusta':
                    var inptext=$(".demoTablea input[name='searchtexta']").val();
                    var seletext=$(".demoTablea").find("dl dd.layui-this").attr("lay-value");
                    console.log(seletext)
                    if((inptext == "")&&(seletext==undefined)){
                        layer.msg("请输入需要搜索的条件");
                        return false;
                    }else if((inptext=="")&&(seletext!=undefined)){
                        layer.msg("请输入需要查询的条件");
                        return false;
                    }else if((inptext!="")&&(seletext==undefined)){
                        layer.msg("请选择查询的字段");
                        return false;
                    }else{
                        var datas={
                            inptext:inptext,
                            column:seletext
                        }
                        searchCusInfo(datas)
                    }
                    break;
            }
        });
        // 未准表头部事件
        table.on('toolbar(notexactlyTableFilter)', function (obj) {
            var layEvent = obj.event;
            switch (layEvent) {
                case 'searchCustb':
                    var inptext=$(".demoTableb input[name='searchtextb']").val();
                    var seletext=$(".demoTableb").find("dl dd.layui-this").attr("lay-value");
                    console.log(seletext)
                    if((inptext == "")&&(seletext==undefined)){
                        layer.msg("请输入需要搜索的条件");
                        return false;
                    }else if((inptext=="")&&(seletext!=undefined)){
                        layer.msg("请输入需要查询的条件");
                        return false;
                    }else if((inptext!="")&&(seletext==undefined)){
                        layer.msg("请选择查询的字段");
                        return false;
                    }else{
                        var datas={
                            inptext:inptext,
                            column:seletext
                        }
                        searchCusInfo(datas)
                    }
                    break;
            }
        });
    });

    //模糊查询
    function searchCusInfo(data) {
        var parm={}
        var toolb;
        var clo;
        var tableName;
        // if(data.column=="RETURN_STATUS"){
        //     if(data.inptext=="部分归还"){
        //         data.inptext=1;
        //     }if(data.inptext=="全部归还"){
        //         data.inptext=2
        //     }if(data.inptext=="未归还"){
        //         data.inptext=0;
        //     }
        // }
        if (topindexPage == 0) {
            parm = {
                column: data.column,
                inptext: data.inptext
            }
            $.ajax({
                type: 'post'
                ,url:'/equipmentScrapping/showScraplogNew'
                , data: parm
                , dataType: 'json',
                success: function (res) {
                    var datas = res.data;
                    layui.table.render({
                        elem: '#Settlement'
                        , page: true //开启分页
                        , url: ''//数据接口
                        ,data:datas
                        , toolbar: '#toolbar'
                        , cols: [[ //标题栏
                            {type: 'checkbox'}
                            , {field: 'scraplogId', title: '申请编号'}
                            , {field: 'applicant', title: '报废申请人'}
                            , {field: 'deptName', title: '报废申请部门'}
                            , {field: 'applicantTime', title: '报废申请时间',templet: function(d) {
                                    return format(d.applicantTime)
                                }}
                            , {field: 'workflowNo', title: '流水号'}
                            , {field: 'scrapReason', title: '报废原因'}
                            , {field: 'memo', title: '备注'}
                            , {width: 200, title: '操作', align: 'center', toolbar: '#barOperation'}
                        ]]
                        , limit: 10
                        ,done:function (res) {
                            if(res.data.length >0){
                                var scraplogId = res.data[0].scraplogId;
                                equipTable("#transferDetail",scraplogId,"#toolbars",col);
                            }else{
                                cequipTable("#transferDetail","#toolbars",col);
                            }
                            $(".demoTable input[name='searchtext']").val(data.inptext);
                            $(".demoTable").find("select[name='modules']").each(function () {
                                // this代表的是<option></option>，对option再进行遍历
                                $(this).children("option").each(function () {
                                    // 判断需要对那个选项进行回显
                                    if (this.value == data.column) {
                                        // 进行回显
                                        $(this).attr("selected", "selected");
                                    }
                                });
                            })
                            layui.form.render('select');
                        }
                    })
                }

            })
        } else if (topindexPage == 1) {
            parm = {
                column: data.column,
                inptext: data.inptext
            }
            $.ajax({
                type: 'post'
                ,url:'/equipmentScrapping/showScraplogWait'
                , data: parm
                , dataType: 'json',
                success: function (res) {
                    var datas = res.data;
                    layui.table.render({
                        elem: '#accurateTable'
                        , url: ''
                        ,data:datas
                        , page: true //开启分页
                        , toolbar: '#approval'
                        , limit: 5 //每页默认显示的数量
                        , limits: [5, 10, 15, 20, 25, 30]
                        , cols: [[ //标题栏
                            {field: 'scraplogId', title: '申请编号'}
                            , {field: 'applicant', title: '报废申请人'}
                            , {field: 'deptName', title: '报废申请部门'}
                            , {field: 'applicantTime', title: '报废申请时间',templet: function(d) {
                                    return format(d.applicantTime)
                                }}
                            , {field: 'workflowNo', title: '流水号'}
                            , {field: 'scrapReason', title: '报废原因'}
                            , {field: 'memo', title: '备注'}
                        ]]
                        ,done:function (res) {
                            if(res.data.length >0){
                                var scraplogId = res.data[0].scraplogId;
                                equipTable("#accurateDetail",scraplogId,"#",ccol)
                            }else{
                                cequipTable("#accurateDetail","#",ccol)
                            }
                            // $("#" + searchColum + "").val($("#" + searchColum + "").val())
                            // $("#colum").find('option[value="' + searchColum + '"]').prop('selected', 'selected');
                            $(".demoTabless input[name='searchtextss']").val(data.inptext);
                            $(".demoTabless").find("select[name='modules']").each(function () {
                                // this代表的是<option></option>，对option再进行遍历
                                $(this).children("option").each(function () {
                                    // 判断需要对那个选项进行回显
                                    if (this.value == data.column) {
                                        // 进行回显
                                        $(this).attr("selected", "selected");
                                    }
                                });
                            })
                            layui.form.render('select');
                        }
                    });
                }
            })
        } else if (topindexPage == 2) {
            parm = {
                column: data.column,
                inptext: data.inptext
            }

            $.ajax({
                type: 'post'
                ,url:'/equipmentScrapping/showScraplogYes'
                , data: parm
                , dataType: 'json',
                success: function (res) {
                    var datas = res.data;

                    layui.table.render({
                        elem: '#approvalTable'
                        , url: ''
                        ,data:datas
                        , page: true //开启分页
                        , toolbar: '#accurate'
                        , limit: 5 //每页默认显示的数量
                        , limits: [5, 10, 15, 20, 25, 30]
                        , cols: [[ //标题栏
                            {field: 'scraplogId', title: '申请编号'}
                            , {field: 'applicant', title: '报废申请人'}
                            , {field: 'deptName', title: '报废申请部门'}
                            , {field: 'applicantTime', title: '报废申请时间',templet: function(d) {
                                    return format(d.applicantTime)
                                }}
                            , {field: 'workflowNo', title: '流水号'}
                            , {field: 'scrapReason', title: '报废原因'}
                            , {field: 'memo', title: '备注'}
                        ]]
                        ,done:function (res) {
                            if(res.data.length >0){
                                var scraplogId = res.data[0].scraplogId
                                equipTable("#approvalDetail",scraplogId,"#",ccol)
                            }else{
                                cequipTable("#approvalDetail","#",ccol)
                            }
                            $(".demoTablea input[name='searchtexta']").val(data.inptext);
                            $(".demoTablea").find("select[name='modules']").each(function () {
                                // this代表的是<option></option>，对option再进行遍历
                                $(this).children("option").each(function () {
                                    // 判断需要对那个选项进行回显
                                    if (this.value == data.column) {
                                        // 进行回显
                                        $(this).attr("selected", "selected");
                                    }
                                });
                            })
                            layui.form.render('select');
                        }
                    });
                }
            })
        } else if (topindexPage == 3) {
            parm = {
                column: data.column,
                inptext: data.inptext
            }
            $.ajax({
                type: 'post'
                , url:'/equipmentScrapping/showScraplogNo'
                , data: parm
                , dataType: 'json',
                success: function (res) {
                    var datas = res.data;
                    layui.table.render({
                        elem: '#notexactlyTable'
                        , url: ''
                        ,data:datas
                        , toolbar: '#notexactly'
                        , page: true //开启分页
                        , limit: 5 //每页默认显示的数量
                        , limits: [5, 10, 15, 20, 25, 30]
                        , cols: [[ //标题栏
                            {field: 'scraplogId', title: '申请编号'}
                            , {field: 'applicant', title: '报废申请人'}
                            , {field: 'deptName', title: '报废申请部门'}
                            , {field: 'applicantTime', title: '报废申请时间',templet: function(d) {
                                    return format(d.applicantTime)
                                }}
                            , {field: 'workflowNo', title: '流水号'}
                            , {field: 'scrapReason', title: '报废原因'}
                            , {field: 'memo', title: '备注'}
                        ]]
                        ,done:function (res) {
                            if(res.data.length >0){
                                var scraplogId = res.data[0].scraplogId;
                                equipTable("#notexactlyDetail",scraplogId,"#",ccol)
                            }else{
                                cequipTable("#notexactlyDetail","#",ccol)
                            }
                            // $("#" + searchColum + "").val($("#" + searchColum + "").val())
                            // $("#colum").find('option[value="' + searchColum + '"]').prop('selected', 'selected');
                            $(".demoTableb input[name='searchtextb']").val(data.inptext);
                            $(".demoTableb").find("select[name='modules']").each(function () {
                                // this代表的是<option></option>，对option再进行遍历
                                $(this).children("option").each(function () {
                                    // 判断需要对那个选项进行回显
                                    if (this.value == data.column) {
                                        // 进行回显
                                        $(this).attr("selected", "selected");
                                    }
                                });
                            })
                            layui.form.render('select');
                        }
                    });
                }
            })
        }
    }
    //将毫秒数转为yyyy-MM-dd格式时间
    function format(t) {
        if(t) return new Date(t).Format("yyyy-MM-dd");
        else return ''
    }
    //设备转移明细表格实例
    function equipTable(gid,logid,tid,col) {
        layui.table.render({
            elem: gid
            ,data:[]
            , url: '/equipmentScrapping/showScraplist?scraplogId='+logid
            ,toolbar:tid
            // ,id:'equip'
            , page: true //开启分页
            , limit: 5 //每页默认显示的数量
            , limits: [5, 10, 15, 20, 25, 30]
            , cols: col
        });
    }
    function cequipTable(gid,tid,col) {
        layui.table.render({
            elem: gid
            ,data:[]
            ,toolbar:tid
            // ,id:'equip'
            , page: true //开启分页
            , limit: 5 //每页默认显示的数量
            , limits: [5, 10, 15, 20, 25, 30]
            , cols: col
        });
    }

</script>
</body>
</html>

